
	
****************************** CHAPTER 7, FIGURE 18: Pro-turnout messages and turnout: JF 2008 & BEPS 2014
tempfile tf1 tf2
************************* JF 2008
use "C:\Users\aesmith2\Dropbox\Work\Data\Brazil_JF 2008 election\Data\JF nbhd survey.dta", clear
*********************** DEVELOP SAMPLING WEIGHTS 
drop if p158_ <=9
	g age = 2008-p158_
g female = (p144_ == 2)
	tab1 female, mi
	display 239385/(239385 + 217411) //This is the proportion of women in the JF population)
	g wt_sex = .52405231/.5830
	replace wt_sex = (1-.52405231)/(1-.5830) if female == 0
recode age (16/19 = 1) (20/24 = 2) (25/29 = 3) (30/34 = 4) (35/39 = 5) (40/44 = 6) (45/49 = 7) (50/54 = 8) (55/59 = 9) ///
	(60/64 = 10) (65/69 = 11) (70/74 = 12) (75/79 = 13) (80/120 = 14), g(agegrouped)
	g agef = agegrouped*10 + female
g wt_agesex = 1
	replace wt_agesex = 1.30006 if agef == 10
	replace wt_agesex = 1.46480 if agef == 11
	replace wt_agesex = 1.89131 if agef == 20
	replace wt_agesex = 2.10230 if agef == 21
	replace wt_agesex = 1.37121 if agef == 30
	replace wt_agesex = 1.13908 if agef == 31
	replace wt_agesex = 1.49916 if agef == 40
	replace wt_agesex = 1.57118 if agef == 41
	replace wt_agesex = 2.32857 if agef == 50
	replace wt_agesex = 2.00751 if agef == 51
	replace wt_agesex = 1.33920 if agef == 60
	replace wt_agesex = 0.93010 if agef == 61
	replace wt_agesex = 1.25433 if agef == 70
	replace wt_agesex = 0.78927 if agef == 71
	replace wt_agesex = 0.81507 if agef == 80
	replace wt_agesex = 0.60531 if agef == 81
	replace wt_agesex = 0.57002 if agef == 90
	replace wt_agesex = 0.56538 if agef == 91
	replace wt_agesex = 0.62034 if agef == 100
	replace wt_agesex = 0.44865 if agef == 101
	replace wt_agesex = 0.47191 if agef == 110
	replace wt_agesex = 0.50520 if agef == 111
	replace wt_agesex = 0.62523 if agef == 120
	replace wt_agesex = 0.55294 if agef == 121
	replace wt_agesex = 0.60012 if agef == 130
	replace wt_agesex = 0.52134 if agef == 131
	replace wt_agesex = 0.37337 if agef == 140
	replace wt_agesex = 0.83114 if agef == 141
g wt_bairro = 1
	replace wt_bairro = 0.531286243 if bairro == "Alto dos Passos"
	replace wt_bairro = 0.456803247 if bairro == "Bairu"
	replace wt_bairro = 2.002438262 if bairro == "Benfica"
	replace wt_bairro = 0.291846909 if bairro == "Bonfim"
	replace wt_bairro = 3.036457558 if bairro == "Centro"
	replace wt_bairro = 0.831999775 if bairro == "Costa Carvalho"
	replace wt_bairro = 0.399442191 if bairro == "Dom Bosco"
	replace wt_bairro = 0.496671456 if bairro == "Fabrica"
	replace wt_bairro = 0.963095037 if bairro == "Francisco Bernardino"
	replace wt_bairro = 0.382243301 if bairro == "Industrial"
	replace wt_bairro = 1.189123931 if bairro == "Linhares"
	replace wt_bairro = 0.383670132 if bairro == "Morro da Gloria"
	replace wt_bairro = 0.800988427 if bairro == "Lourdes"
	replace wt_bairro = 0.36884402 if bairro == "Poco Rico"
	replace wt_bairro = 1.878052914 if bairro == "Progresso"
	replace wt_bairro = 1.518275204 if bairro == "Santa Luzia"
	replace wt_bairro = 0.65455163 if bairro == "Santa Rita"
	replace wt_bairro = 1.028535521 if bairro == "Santa Terezinha"
	replace wt_bairro = 0.953952699 if bairro == "Santo Antonio"
	replace wt_bairro = 1.562597412 if bairro == "Sao Benedito"
	replace wt_bairro = 2.953369209  if bairro == "Sao Mateus"
	replace wt_bairro = 0.462369179 if bairro == "Vitorino Braga"
g wt = wt_agesex*wt_bairro
g wt_withhh = wt*p152_numadults
	replace wt_withhh = wt if p152_numadults == 0
*********************** END DEVELOP SAMPLING WEIGHTS ******************************************
************** data set up
g voted5oct = (p46_ == 1)
	g voted26oct = (p54_ == 1)
	g voted2elections = voted5oct + voted26oct
recode voted2elections (0 1 = 0) (2=1)
recode p17_religion (1=1) (2 5 = 2) (8 9 . = 3) (3 4 6 = 4), g(denom)
	lab def denom 1 "Catholic" 2 "Evangelical/Protestant" 3 "None" 4 "Other Religion"
	lab val denom denom
replace denom = 2 if p17_religoutra == "cristã" | p17_religoutra == "cristão" | p17_religoutra == "Ecumênico" | p17_religion == 5
replace denom = 4 if p17_religoutra == "Judeu" | p17_religoutra == "mulçulmana" | p17_religoutra == "xamanismo"
replace denom = 3 if p17_religoutra == "Agnóstico" | p17_religoutra == "indefinido" | p17_religoutra == "nenhuma" | ///
			p17_religoutra == "nr" | p17_religoutra == "não tem" 
g churchconscience = (p23_ == 1)
g churchcands = (p24_ == 1)
g churchfreq = (5-p21_)/4 if p21_ < 8
	replace churchfreq = 0 if p18_ != 1
summ age 
	replace age = (age-r(min))/(r(max)-r(min))
summ p151_ if p151_ < 88 
	g educ = (p151_-r(min))/(r(max)-r(min)) if p151_ < 88
logit voted2elections i.churchcands i.churchconscience i.denom churchfreq educ female age [pweight=wt] if churchfreq > .7
	margins churchcands churchconscience , level(90) post
	parmest, saving(`tf1', replace) level(90)

	
************************* BEPS 2014
use "C:\Users\aesmith2\Dropbox\Work\Data\BEPS 2014\Data from IDB site\BEPS_2014_v3.dta", clear
**** simplify wave codings
drop if idtelefone == 59 & wave == 3 // DROP WAVE 3 FOR ONE INDIVIDUAL WHO WAS INTERVIEWED ACCIDENTALLY IN BOTH WAVES 2 AND 3
recode wave (1=1) (2 3 = 2) (4 5 = 3) (6 = 4) (7 = 5), g(newwave)
move newwave wave
xtset idtelefone newwave
***** STABLE VALUES OF WAVE 1 VARIABLES
foreach var in val1 val2 val2a p5 pk1 pk2 pk3 pk4 pk5 pol1 rel1 l1 {
egen `var'1 = mean(`var'), by(idtelefone)
	replace `var' = `var'1
	drop `var'1
}
g churchfreq = (5-p5)/4
	lab var churchfreq "Frequency of Church Attendance"
recode churchfreq (0/.5 = 0) (.75/1 = 1), g(churchfreq_dichot)
recode religion (1=1) (2 3 = 2) (9=3) (4/8 10 = 4) , g(religion2)
	lab def religion2 1 "Catholic" 2 "Evangelical/Protestant" 3 "No Religion" 4 "Other Religion"
	lab val religion2 religion2
recode rel2 (2 .a .b .c = 0), g(pastortalkedelections)
	g pastortalkedelections_w6 = 0 if wave == 6
	forvalues i = 1/5 {
		recode pastortalkedelections_w6 (0 . = 1) if l`i'.pastortalkedelections == 1
	}
recode rel3 (2 .a .b .c = 0), g(church_proturnout)
recode educ (1 2 = 0) (3 5 6 = 1) (4 7 8 = 2) (9 10 = 3) (11 12 13 14 = 4), g(educr)
	lab var educr "Education" 
	lab def educr 0 "No School" 1 "Primary School" 2 "Middle School" 3 "High School" 4 "Higher Education"
	lab val educr educr
replace wealth = wealth/10
	lab var wealth "Household Wealth"
g urban = 2-urb_rur
recode idade (16/25=1) (26/35=2) (36/45=3) (46/55=4) (56/65=5) (65/110=6), g(edad)
	summ idade
	replace idade=(idade-r(min))/(r(max)-r(min))
lab var mulher "Woman"
recode vb1 (.a .b = 14) if wave < 6
g vote_w1 = l3.vb1 if wave == 6
	recode vote_w1 (5/14=14)
recode vb1 (13 14 .a .b = 0) (1/12=1), g(hasvote)
logit hasvote i.church_proturnout i.pastortalkedelections_w6 i.religion2 churchfreq educr mulher i.edad wealth urban if wave == 6 
	margins i.pastortalkedelections_w6 i.church_proturnout , level(90) post
	parmest, saving(`tf2', replace) level(90)
************************* CREATE FIGURE
dsconcat `tf1' `tf2'
egen study = seq(), f(1) t(2) block(4)
	lab def study 1 "Juiz de Fora 2008" 2 "Brazil 2014"
	lab val study study
egen var = seq(), f(1) t(2) block(2)
	lab def var 1 "Candidate Discussion" 2 "Turnout Message"
	lab val var var
egen messages = seq(), f(0) t(1)
egen xaxis = seq(), f(1) t(4) 
	replace xaxis = xaxis + var-1
graph twoway (bar estimate xaxis if messages == 0, lcolor(black) fcolor(gs5)) || ///
			(bar estimate xaxis if messages == 1, lcolor(black) fcolor(gs12)) || ///
			(rspike min90 max90 xaxis, lcolor(black)), ///
		by(study, col(2) ///
				note("Sources: Juiz de Fora Networks and Neighborhoods Study, 2008 and Brazilian Electoral Panel Study 2014. Marginal effects from logistic " ///
					"regression models, controlling for religious affiliation, church attendance, education, gender, age, wealth, and urban residence.", span size(vsmall)) ///
				graphregion(fcolor(white) lcolor(black))    ) ///
		legend(order(1 "No Messages" 2 "Messages") cols(2) size(small)) subtitle(, lcolor(black)) plotregion(lcolor(black)) ///
		xlabel(1.5 "Candidate Discussion" 4.5 "Turnout Messages") xtitle("") ///
		ytitle("Probability of Having Voted", margin(small)) 
****************************** END FIGURE 2: Pro-turnout messages and turnout: JF 2008 & BEPS 2014
